<template>
  <div id="app" v-if="isRouterAlive">
    <el-container> <AddHeader /> <router-view></router-view></el-container>
  </div>
</template>

<script>
import AddHeader from "./components/header.vue";
import AddFooter from "./components/footer.vue";

export default {
  name: "App",
  components: {
    AddHeader,
    AddFooter,
  },
  provide() {
    //父组件中通过provide来提供变量，在子组件中通过inject来注入变量。
    return {
      reload: this.reload,
    };
  },
  data() {
    return {
      isRouterAlive: true, //控制视图是否显示的变量
    };
  },
  methods: {
    reload() {
      this.isRouterAlive = false; //先关闭，
      this.$nextTick(function () {
        this.isRouterAlive = true; //再打开
      });
    },
  },
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-color: rgb(148, 148, 148);
  text-align: center;
  color: #2c3e50;
  margin: 0;
}
</style>
